<?php
namespace app\home\controller;

use cmf\controller\HomeBaseController;
use app\common\model\MytaskModel;
use app\common\model\RemindModel;
use app\common\model\AnserModel;
use app\common\model\LessonNameModel;
use app\common\model\LessonModel;
use app\common\model\ClassprogressModel;

//课程信息
class MytaskController extends HomeBaseController
{
	public $data_tem;
	public function __construct(){
		parent::__construct();
		$this->data_tem = ClassprogressModel::where('mid',13)->select()->toArray();
	}
	
	public function index(){
		$param = $this->request->param();
		$url = cmf_url('index_1',$param);
		$this->assign('title','');
		$this->assign('url',$url);
		return $this->fetch(":index");
	}

	public function index_1(){
		$param = $this->request->param();
		$data = MytaskModel::get($param['id'],'user');
		$day = RemindModel::where('user_id',$data['uid'])->value('day');
		$url = cmf_url('index_2',$param);
		$this->assign('url',$url);
		$this->assign('data',$data);
		$this->assign('day',$day);
		return $this->fetch(":index_1");
	}

	public function index_2(){
		$param = $this->request->param();
		$data = AnserModel::where('taskid',$param['id'])->where('pid',4)->field('content')->find();
		$content = explode(',', $data['content']);
		$content = explode('|', $content[0]);
		$url = cmf_url('index_3',$param);
		$this->assign('url',$url);
		$this->assign('content',$content);
		return $this->fetch(":index_2");
	}

	public function index_3(){
		$param = $this->request->param();

		$data = AnserModel::where('taskid',$param['id'])->where('pid',3)->field('content')->find();
      
		$content = explode(',', $data['content']);
		$contentss = '';
		for ($i=0; $i < count($content)-1; $i++) { 
			if(!empty($content[$i])){
				$contents = explode('|', $content[$i]);
				$contentss[$i] = $contents[1];
			}
			
		}
		
		$data = MytaskModel::get($param['id']);
		$lesson_ids = RemindModel::where('user_id',$data['uid'])->value('lesson_ids');
		$lesson_array = explode(',',$lesson_ids);
		//课程ID
		foreach ($lesson_array as $key => $value) {
			$name_id = LessonModel::where('lesson_id',$value)->value('name_id');
			if(!empty($name_id)){
				$lesson_arrayss[] = $name_id;
			}
		}
		
		$lesson_arrays = array_shift($lesson_arrayss); 
		//dump($lesson_arrays);
		$lesson_ids = implode(',',$lesson_arrayss);

		$url = cmf_url('index_4',['id'=>$param['id'],'lesson_ids'=>$lesson_ids,'lesson_id'=>$lesson_arrays]);
		//dump($url); 

		$this->assign('url',$url);
		$this->assign('contentss',$contentss);
		return $this->fetch(":index_3");
	}

	public function index_4(){
		
		$param = $this->request->param();
		//dump($param);
		$data = LessonNameModel::get($param['lesson_id']);
     
		$reply = '';
		foreach ($this->data_tem as $key => $value) {
			if($data['title'] == $value['question']){
				$reply = $value['reply'];
				break;
			}
		}

		if (empty($param['lesson_ids'])) {
			$url = cmf_url('index_5',['id'=>$param['id']]);
		}else{
			$lesson_array = explode(',',$param['lesson_ids']);
			$lesson_arrays = array_shift($lesson_array);  
		
			$lesson_ids = implode(',',$lesson_array);
			$url = cmf_url('index_4',['id'=>$param['id'],'lesson_ids'=>$lesson_ids,'lesson_id'=>$lesson_arrays]);
		}
		

		$this->assign('url',$url);
		$this->assign('reply',$reply);
		$this->assign('data',$data);
		return $this->fetch(":index_4");
	}

	public function index_5(){
		$param = $this->request->param();
		$data = MytaskModel::get($param['id'],'user');
		//dump($data);
		$this->assign('data',$data);
		$url = cmf_url('index_6',$param);
		$this->assign('url',$url);
		return $this->fetch(":index_5");

	}
	public function index_6(){
		$param = $this->request->param();
		$data = MytaskModel::get($param['id'],'user');
		$this->assign('data',$data);
		$url = cmf_url('index_7',$param);
		$this->assign('url',$url);
		return $this->fetch(":index_6");

	}
	public function index_7(){
		
		return $this->fetch(":end");

	}
}
